package com.zxl.controller;

import com.zxl.domain.UserInfo;
import com.zxl.service.impl.UserSerciceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/user")
//@CrossOrigin
public class UserController {
    @Autowired
    private UserSerciceImpl userSercice;

    @RequestMapping("/findall")
    public ModelAndView findAllUser() {
        ModelAndView mv = new ModelAndView();
        List<UserInfo> allUser = userSercice.findAllUser();
        mv.setViewName("user_list");
        mv.addObject("user", allUser);
        System.out.println(allUser);
        System.out.println("Controller---------findAllUser");
        return mv;
    }

    @RequestMapping("/find")
    @ResponseBody
    public List<UserInfo> findAll() {
        List<UserInfo> allUser = new ArrayList<>();
        UserInfo userInfo1 = new UserInfo();
        userInfo1.setId(0);
        userInfo1.setUsername("xx");
        userInfo1.setPassword("123");
        UserInfo userInfo2 = new UserInfo();
        userInfo2.setId(1);
        userInfo2.setUsername("jj");
        userInfo2.setPassword("123");
        UserInfo userInfo3 = new UserInfo();
        userInfo3.setId(2);
        userInfo3.setUsername("ss");
        userInfo3.setPassword("123");
        allUser.add(userInfo1);
        allUser.add(userInfo2);
        allUser.add(userInfo3);
        return allUser;
    }
}
